﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nollie.IntegrationTests;

namespace Nollie
{
	[TestClass]
	public class CacheItemTests
	{
		[TestMethod]
		[ExpectedException(typeof(NollieException))]
		public void Validate_should_throw_exception_if_expiry_date_is_expired()
		{
			var item = TestDataHelper.GetValidCacheItem();
			item.ExpiryDate = DateTime.Now.AddDays(-1);

			item.Validate();
		}
		[TestMethod]
		[ExpectedException(typeof(NollieException))]
		public void Validate_should_throw_exception_if_key_is_empty()
		{
			var item = TestDataHelper.GetValidCacheItem();
			item.Key = string.Empty;

			item.Validate();
		}
		[TestMethod]
		[ExpectedException(typeof(NollieException))]
		public void Validate_should_throw_exception_if_value_is_null()
		{
			var item = TestDataHelper.GetValidCacheItem();
			item.Value = null;

			item.Validate();
		}
		[TestMethod]
		public void Validate_should_not_throw_exception_when_an_item_is_valid()
		{
			var item = TestDataHelper.GetValidCacheItem();

			item.Validate();
		}
		[TestMethod]
		public void IsExpired_should_return_true_if_expiry_date_of_item_is_older_than_now()
		{
			var item = TestDataHelper.GetValidCacheItem();
			item.ExpiryDate = DateTime.Now.AddDays(-1);

			Assert.AreEqual(true, item.IsExpired());
		}
		[TestMethod]
		public void IsExpired_should_return_false_if_expiry_date_of_item_is_newer_than_now()
		{
			var item = TestDataHelper.GetValidCacheItem();

			Assert.AreEqual(false, item.IsExpired());
		}
	}
}
